package com.platform.controller;

import com.platform.entity.GoodsCategoryEntity;
import com.platform.service.GoodsCategoryService;
import com.platform.entity.CategoryEntity;
import com.platform.service.CategoryService;

import com.platform.utils.PageUtils;
import com.platform.utils.Query;
import com.platform.utils.R;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.ArrayList;

@RestController
@RequestMapping("goodsCategory")
public class GoodsCategoryController {
    @Autowired
    private GoodsCategoryService goodsCategoryService;
    @Autowired
    private CategoryService categoryService;

    /*@RequestMapping("/query")
    @RequiresPermissions("goods:list")
    public R query(@RequestBody Integer goodId) {
        List<Integer> categoryId = goodsCategoryService.queryObject(goodId);
        List<String> categoryName = new ArrayList<>();
        for(int i = 0; i < categoryId.size(); i++){
            categoryName.set(i, categoryService.queryObject(categoryId.get(i)).getName());
        }
        GoodsCategoryEntity goodsCategoryEntity = new GoodsCategoryEntity();
        goodsCategoryEntity.setGoodId(goodId);
        goodsCategoryEntity.setCategoryId(categoryId);
        goodsCategoryEntity.setCategoryName(categoryName);
        return R.ok().put("goodsCategory", goodsCategoryEntity);
    }

    @RequestMapping("/save")
    @RequiresPermissions("goods:save")
    public R save(@RequestParam String categoryName) {
        String[] categoryNames = categoryName.split("=");
        Integer goodId = Integer.parseInt(categoryNames[1]);
        String[] category = categoryNames[0].split("#");
        for(int i = 0; i < category.length; i++){
            GoodsCategoryEntity goodsCategoryEntity = new GoodsCategoryEntity();
            goodsCategoryEntity.setCategoryId(Integer.parseInt(category[i]));
            goodsCategoryEntity.setGoodId(goodId);
            goodsCategoryService.save(goodsCategoryEntity);
        }
        return R.ok();
    }*/
}
